package tp.pr1;


public class Interpreter {
	/**	Genera la instruccion a partir de una linea de texto introducida como comando.
	 * 
	 * @param 	line
	 * @return	instruction: Resultado de parsear el comando
	 */
	public Instruction generateInstruction (String line){
		line = line.toUpperCase();
		String[] command = line.split(" ");
				
		
		if (command.length > 0) {
			switch (command[0]){
			case (COMMAND_MOVE):	return new Instruction(Action.MOVE);
			case (COMMAND_TURN):	{
				
				if (command.length > 1) {
					switch (command[1]) { //LEFT RIGHT UNKNOWN
					case (COMMAND_TURN_LEFT):	return new Instruction(Action.TURN,Rotation.LEFT);
					case (COMMAND_TURN_RIGHT):	return new Instruction(Action.TURN,Rotation.RIGHT);
					default:		return new Instruction(Action.TURN,Rotation.UNKNOWN);
					}
				} else {
					return new Instruction(Action.TURN,Rotation.UNKNOWN);
				}
			}
			case (COMMAND_HELP):	return new Instruction(Action.HELP);
			case (COMMAND_QUIT):	return new Instruction(Action.QUIT);
			default :		return new Instruction();
			}
		} else {
			return new Instruction();
		}
		
	}
	/**	Devuelve la ayuda
	 * 
	 * @return HELP: String con la ayuda
	 */
	public String interpreterHelp (){
		return HELP;
	}
	
	//constantes de comandos para poder cambiarlas luego a otros idiomas
	private static final String COMMAND_MOVE = "MOVE";
	private static final String COMMAND_TURN = "TURN";
	private static final String COMMAND_TURN_LEFT = "LEFT";
	private static final String COMMAND_TURN_RIGHT = "RIGHT";
	private static final String COMMAND_HELP = "HELP";
	private static final String COMMAND_QUIT = "QUIT";
	
	
	//line separator
	public static final String LINE_SEPARATOR = System.getProperty("line.separator");
	
	//constantes de la ayuda

	
	
	private static final String HELP = "The valid instructions for "+ RobotEngine.ROBOT_NAME + " are:" +
			LINE_SEPARATOR + "  " + COMMAND_MOVE + LINE_SEPARATOR + "  "+ COMMAND_TURN+" <" + COMMAND_TURN_LEFT + " | " +
			COMMAND_TURN_RIGHT + ">" + LINE_SEPARATOR + "  " + COMMAND_HELP + LINE_SEPARATOR + "  " + COMMAND_QUIT;
	

}
